// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 

package com.sec.android.widgetapp.calculator;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.*;
import android.view.animation.*;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

public class Panel extends LinearLayout
{
    class PanelOnGestureListener
        implements android.view.GestureDetector.OnGestureListener
    {

        public boolean onDown(MotionEvent motionevent)
        {
            scrollY = 0.0F;
            scrollX = 0.0F;
            initChange();
            return true;
        }

        public boolean onFling(MotionEvent motionevent, MotionEvent motionevent1, float f, float f1)
        {
            mState = State.FLYING;
            Panel panel = Panel.this;
            float f2;
            if(mOrientation == 1)
                f2 = f1;
            else
                f2 = f;
            panel.mVelocity = f2;
            post(startAnimation);
            return true;
        }

        public void onLongPress(MotionEvent motionevent)
        {
        }

        public boolean onScroll(MotionEvent motionevent, MotionEvent motionevent1, float f, float f1)
        {
            mState = State.TRACKING;
            float f2 = 0.0F;
            float f3 = 0.0F;
            if(mOrientation == 1)
            {
                scrollY = scrollY - f1;
                if(mPosition == 0)
                    f2 = ensureRange(scrollY, -mContentHeight, 0);
                else
                    f2 = ensureRange(scrollY, 0, mContentHeight);
            } else
            {
                scrollX = scrollX - f;
                if(mPosition == 2)
                    f3 = ensureRange(scrollX, -mContentWidth, 0);
                else
                    f3 = ensureRange(scrollX, 0, mContentWidth);
            }
            if(f3 != mTrackX || f2 != mTrackY)
            {
                mTrackX = f3;
                mTrackY = f2;
                invalidate();
            }
            return true;
        }

        public void onShowPress(MotionEvent motionevent)
        {
        }

        public boolean onSingleTapUp(MotionEvent motionevent)
        {
            return false;
        }

        public void setScroll(int i, int j)
        {
            scrollX = i;
            scrollY = j;
        }

        float scrollX;
        float scrollY;
        final Panel this$0;

        PanelOnGestureListener()
        {
            this$0 = Panel.this;
            super();
        }
    }

    public static interface OnPanelListener
    {

        public abstract boolean onPanelClicked(Panel panel);

        public abstract void onPanelClosed(Panel panel);

        public abstract void onPanelOpened(Panel panel);
    }

    private static final class State extends Enum
    {

        public static State valueOf(String s)
        {
            return (State)Enum.valueOf(com/sec/android/widgetapp/calculator/Panel$State, s);
        }

        public static State[] values()
        {
            return (State[])$VALUES.clone();
        }

        private static final State $VALUES[];
        public static final State ABOUT_TO_ANIMATE;
        public static final State ANIMATING;
        public static final State FLYING;
        public static final State READY;
        public static final State TRACKING;

        static 
        {
            ABOUT_TO_ANIMATE = new State("ABOUT_TO_ANIMATE", 0);
            ANIMATING = new State("ANIMATING", 1);
            READY = new State("READY", 2);
            TRACKING = new State("TRACKING", 3);
            FLYING = new State("FLYING", 4);
            State astate[] = new State[5];
            astate[0] = ABOUT_TO_ANIMATE;
            astate[1] = ANIMATING;
            astate[2] = READY;
            astate[3] = TRACKING;
            astate[4] = FLYING;
            $VALUES = astate;
        }

        private State(String s, int i)
        {
            super(s, i);
        }
    }


    public Panel(Context context, AttributeSet attributeset)
    {
        super(context, attributeset);
        mAniEnd = true;
        mTouchable = true;
        touchListener = new android.view.View.OnTouchListener() {

            public boolean onTouch(View view, MotionEvent motionevent)
            {
                if(mState != State.ANIMATING) goto _L2; else goto _L1
_L1:
                boolean flag = false;
_L4:
                return flag;
_L2:
                int j = motionevent.getAction();
                if(j == 0)
                {
                    mTouchable = panelListener.onPanelClicked(Panel.this);
                    if(!mTouchable)
                    {
                        flag = true;
                        continue; /* Loop/switch isn't completed */
                    }
                    if(mBringToFront)
                        bringToFront();
                    initX = 0;
                    initY = 0;
                    if(mContent.getVisibility() == 8)
                        if(mOrientation == 1)
                        {
                            int l;
                            if(mPosition == 0)
                                l = -1;
                            else
                                l = 1;
                            initY = l;
                        } else
                        {
                            int k;
                            if(mPosition == 2)
                                k = -1;
                            else
                                k = 1;
                            initX = k;
                        }
                    setInitialPosition = true;
                } else
                {
                    if(!mTouchable)
                    {
                        flag = true;
                        continue; /* Loop/switch isn't completed */
                    }
                    if(setInitialPosition)
                    {
                        initX = initX * mContentWidth;
                        initY = initY * mContentHeight;
                        mGestureListener.setScroll(initX, initY);
                        setInitialPosition = false;
                        initX = -initX;
                        initY = -initY;
                    }
                    motionevent.offsetLocation(initX, initY);
                }
                if(!mGestureDetector.onTouchEvent(motionevent))
                {
                    if(!mTouchable)
                    {
                        flag = true;
                        continue; /* Loop/switch isn't completed */
                    }
                    if(j == 1)
                        post(startAnimation);
                }
                flag = false;
                if(true) goto _L4; else goto _L3
_L3:
            }

            int initX;
            int initY;
            boolean setInitialPosition;
            final Panel this$0;

            
            {
                this$0 = Panel.this;
                super();
            }
        }
;
        clickListener = new android.view.View.OnClickListener() {

            public void onClick(View view)
            {
                if(mBringToFront)
                    bringToFront();
                if(initChange())
                    post(startAnimation);
            }

            final Panel this$0;

            
            {
                this$0 = Panel.this;
                super();
            }
        }
;
        startAnimation = new Runnable() {

            public void run()
            {
                int j;
                int k;
                int l;
                int i1;
                int k1;
                j = 0;
                k = 0;
                l = 0;
                i1 = 0;
                if(mState == State.FLYING)
                {
                    Panel panel2 = Panel.this;
                    Panel panel1;
                    boolean flag2;
                    boolean flag3;
                    if(mPosition == 0 || mPosition == 2)
                        flag2 = true;
                    else
                        flag2 = false;
                    if(mVelocity > 0.0F)
                        flag3 = true;
                    else
                        flag3 = false;
                    panel2.mIsShrinking = flag2 ^ flag3;
                }
                if(mOrientation == 1)
                {
                    int l1 = mContentHeight;
                    if(!mIsShrinking)
                    {
                        if(mPosition == 0)
                            l = -l1;
                        else
                            l = l1;
                    } else
                    if(mPosition == 0)
                        i1 = -l1;
                    else
                        i1 = l1;
                    if(mState == State.TRACKING)
                    {
                        if(Math.abs(mTrackY - (float)l) < Math.abs(mTrackY - (float)i1))
                        {
                            panel1 = Panel.this;
                            boolean flag1;
                            if(!mIsShrinking)
                                flag1 = true;
                            else
                                flag1 = false;
                            panel1.mIsShrinking = flag1;
                            i1 = l;
                        }
                        l = (int)mTrackY;
                    } else
                    if(mState == State.FLYING)
                        l = (int)mTrackY;
                    if(mState == State.FLYING && mLinearFlying)
                        k1 = Math.max((int)(1000F * Math.abs((float)(i1 - l) / mVelocity)), 20);
                    else
                        k1 = (mDuration * Math.abs(i1 - l)) / mContentHeight;
                } else
                {
                    int j1 = mContentWidth;
                    if(!mIsShrinking)
                    {
                        if(mPosition == 2)
                            j = -j1;
                        else
                            j = j1;
                    } else
                    if(mPosition == 2)
                        k = -j1;
                    else
                        k = j1;
                    if(mState == State.TRACKING)
                    {
                        if(Math.abs(mTrackX - (float)j) < Math.abs(mTrackX - (float)k))
                        {
                            Panel panel = Panel.this;
                            boolean flag;
                            if(!mIsShrinking)
                                flag = true;
                            else
                                flag = false;
                            panel.mIsShrinking = flag;
                            k = j;
                        }
                        j = (int)mTrackX;
                    } else
                    if(mState == State.FLYING)
                        j = (int)mTrackX;
                    if(mState == State.FLYING && mLinearFlying)
                        k1 = Math.max((int)(1000F * Math.abs((float)(k - j) / mVelocity)), 20);
                    else
                        k1 = (mDuration * Math.abs(k - j)) / mContentWidth;
                }
                mTrackX = mTrackY = 0.0F;
                if(k1 != 0) goto _L2; else goto _L1
_L1:
                mState = State.READY;
                if(mIsShrinking)
                    mContent.setVisibility(8);
                postProcess();
_L4:
                return;
_L2:
                TranslateAnimation translateanimation;
                translateanimation = new TranslateAnimation(j, k, l, i1);
                translateanimation.setDuration(k1);
                translateanimation.setAnimationListener(animationListener);
                if(mState != State.FLYING || !mLinearFlying)
                    break; /* Loop/switch isn't completed */
                translateanimation.setInterpolator(new LinearInterpolator());
_L6:
                startAnimation(translateanimation);
                if(true) goto _L4; else goto _L3
_L3:
                if(mInterpolator == null) goto _L6; else goto _L5
_L5:
                translateanimation.setInterpolator(mInterpolator);
                  goto _L6
            }

            final Panel this$0;

            
            {
                this$0 = Panel.this;
                super();
            }
        }
;
        animationListener = new android.view.animation.Animation.AnimationListener() {

            public void onAnimationEnd(Animation animation)
            {
                mState = State.READY;
                if(mIsShrinking)
                    mContent.setVisibility(8);
                postProcess();
            }

            public void onAnimationRepeat(Animation animation)
            {
            }

            public void onAnimationStart(Animation animation)
            {
                mState = State.ANIMATING;
            }

            final Panel this$0;

            
            {
                this$0 = Panel.this;
                super();
            }
        }
;
        TypedArray typedarray = context.obtainStyledAttributes(attributeset, com.sec.android.app.calculator.R.styleable.Panel);
        mDuration = typedarray.getInteger(0, 300);
        mPosition = typedarray.getInteger(1, 1);
        mLinearFlying = typedarray.getBoolean(4, false);
        mWeight = typedarray.getFraction(5, 0, 1, 0.0F);
        if(mWeight < 0.0F || mWeight > 1.0F)
            mWeight = 0.0F;
        mOpenedHandle = typedarray.getDrawable(6);
        mClosedHandle = typedarray.getDrawable(7);
        IllegalArgumentException illegalargumentexception = null;
        mHandleId = typedarray.getResourceId(2, 0);
        if(mHandleId == 0)
            illegalargumentexception = new IllegalArgumentException((new StringBuilder()).append(typedarray.getPositionDescription()).append(": The handle attribute is required and must refer to a valid child.").toString());
        mContentId = typedarray.getResourceId(3, 0);
        if(mContentId == 0)
            illegalargumentexception = new IllegalArgumentException((new StringBuilder()).append(typedarray.getPositionDescription()).append(": The content attribute is required and must refer to a valid child.").toString());
        typedarray.recycle();
        if(illegalargumentexception != null)
            throw illegalargumentexception;
        int i;
        if(mPosition == 0 || mPosition == 1)
            i = 1;
        else
            i = 0;
        mOrientation = i;
        setOrientation(mOrientation);
        mState = State.READY;
        mGestureListener = new PanelOnGestureListener();
        mGestureDetector = new GestureDetector(mGestureListener);
        mGestureDetector.setIsLongpressEnabled(false);
        setBaselineAligned(false);
    }

    private float ensureRange(float f, int i, int j)
    {
        return Math.min(Math.max(f, i), j);
    }

    private void postProcess()
    {
        if(mIsShrinking && mClosedHandle != null)
            mHandle.setBackgroundDrawable(mClosedHandle);
        else
        if(!mIsShrinking && mOpenedHandle != null)
            mHandle.setBackgroundDrawable(mOpenedHandle);
        if(panelListener != null)
            if(mIsShrinking)
                panelListener.onPanelClosed(this);
            else
                panelListener.onPanelOpened(this);
    }

    protected void dispatchDraw(Canvas canvas)
    {
        if(mState == State.ABOUT_TO_ANIMATE && !mIsShrinking)
        {
            int i;
            if(mOrientation == 1)
                i = mContentHeight;
            else
                i = mContentWidth;
            if(mPosition == 2 || mPosition == 0)
                i = -i;
            if(mOrientation == 1)
                canvas.translate(0.0F, i);
            else
                canvas.translate(i, 0.0F);
        }
        if(mState == State.TRACKING || mState == State.FLYING)
            canvas.translate(mTrackX, mTrackY);
        super.dispatchDraw(canvas);
    }

    public Drawable getClosedHandle()
    {
        return mClosedHandle;
    }

    public View getContent()
    {
        return mContent;
    }

    public View getHandle()
    {
        return mHandle;
    }

    public boolean initChange()
    {
        boolean flag1;
        if(mState != State.READY)
        {
            flag1 = false;
        } else
        {
            mState = State.ABOUT_TO_ANIMATE;
            boolean flag;
            if(mContent.getVisibility() == 0)
                flag = true;
            else
                flag = false;
            mIsShrinking = flag;
            if(!mIsShrinking)
                mContent.setVisibility(0);
            flag1 = true;
        }
        return flag1;
    }

    public boolean isOpen()
    {
        boolean flag;
        if(mContent.getVisibility() == 0)
            flag = true;
        else
            flag = false;
        return flag;
    }

    protected void onAttachedToWindow()
    {
        super.onAttachedToWindow();
        android.view.ViewParent viewparent = getParent();
        if(viewparent != null && (viewparent instanceof FrameLayout))
            mBringToFront = true;
    }

    protected void onFinishInflate()
    {
        super.onFinishInflate();
        mHandle = findViewById(mHandleId);
        if(mHandle == null)
        {
            String s1 = getResources().getResourceEntryName(mHandleId);
            throw new RuntimeException((new StringBuilder()).append("Your Panel must have a child View whose id attribute is 'R.id.").append(s1).append("'").toString());
        }
        mHandle.setOnTouchListener(touchListener);
        mHandle.setOnClickListener(clickListener);
        mContent = findViewById(mContentId);
        if(mContent == null)
        {
            String s = getResources().getResourceEntryName(mHandleId);
            throw new RuntimeException((new StringBuilder()).append("Your Panel must have a child View whose id attribute is 'R.id.").append(s).append("'").toString());
        }
        removeView(mHandle);
        removeView(mContent);
        View view;
        View view1;
        if(mPosition == 0 || mPosition == 2)
            view = mContent;
        else
            view = mHandle;
        addView(view);
        if(mPosition == 0 || mPosition == 2)
            view1 = mHandle;
        else
            view1 = mContent;
        addView(view1);
        if(mOpenedHandle != null)
            mHandle.setBackgroundDrawable(mOpenedHandle);
        mContent.setClickable(true);
        mContent.setVisibility(0);
        if(mWeight > 0.0F)
        {
            android.view.ViewGroup.LayoutParams layoutparams = mContent.getLayoutParams();
            if(mOrientation == 1)
                layoutparams.height = -1;
            else
                layoutparams.width = -1;
            mContent.setLayoutParams(layoutparams);
        }
    }

    protected void onLayout(boolean flag, int i, int j, int k, int l)
    {
        super.onLayout(flag, i, j, k, l);
        mContentWidth = mContent.getWidth();
        mContentHeight = mContent.getHeight();
    }

    protected void onMeasure(int i, int j)
    {
        if(mWeight > 0.0F && mContent.getVisibility() == 0)
        {
            View view = (View)getParent();
            if(view != null)
                if(mOrientation == 1)
                    j = android.view.View.MeasureSpec.makeMeasureSpec((int)((float)view.getHeight() * mWeight), 0x40000000);
                else
                    i = android.view.View.MeasureSpec.makeMeasureSpec((int)((float)view.getWidth() * mWeight), 0x40000000);
        }
        super.onMeasure(i, j);
    }

    public void setAniEnd(boolean flag)
    {
        mAniEnd = flag;
    }

    public void setOnPanelListener(OnPanelListener onpanellistener)
    {
        panelListener = onpanellistener;
    }

    private android.view.animation.Animation.AnimationListener animationListener;
    android.view.View.OnClickListener clickListener;
    private boolean mAniEnd;
    private boolean mBringToFront;
    private Drawable mClosedHandle;
    private View mContent;
    private int mContentHeight;
    private int mContentId;
    private int mContentWidth;
    private int mDuration;
    private GestureDetector mGestureDetector;
    private PanelOnGestureListener mGestureListener;
    private View mHandle;
    private int mHandleId;
    private Interpolator mInterpolator;
    private boolean mIsShrinking;
    private boolean mLinearFlying;
    private Drawable mOpenedHandle;
    private int mOrientation;
    private int mPosition;
    private State mState;
    private boolean mTouchable;
    private float mTrackX;
    private float mTrackY;
    private float mVelocity;
    private float mWeight;
    private OnPanelListener panelListener;
    Runnable startAnimation;
    android.view.View.OnTouchListener touchListener;



/*
    static State access$002(Panel panel, State state)
    {
        panel.mState = state;
        return state;
    }

*/




/*
    static boolean access$102(Panel panel, boolean flag)
    {
        panel.mTouchable = flag;
        return flag;
    }

*/



/*
    static boolean access$1102(Panel panel, boolean flag)
    {
        panel.mIsShrinking = flag;
        return flag;
    }

*/



/*
    static float access$1202(Panel panel, float f)
    {
        panel.mVelocity = f;
        return f;
    }

*/



/*
    static float access$1302(Panel panel, float f)
    {
        panel.mTrackY = f;
        return f;
    }

*/





/*
    static float access$1602(Panel panel, float f)
    {
        panel.mTrackX = f;
        return f;
    }

*/












}
